//
//  QDBookDoctorRadioCell.m
//  simulateQuickDoctor
//
//  Created by 梁家伟 on 17/3/23.
//  Copyright © 2017年 PipiXia. All rights reserved.
//

#import "QDBookDoctorRadioCell.h"

@interface QDBookDoctorRadioCell ()

@property(nonatomic,assign)NSUInteger selectedBtnTag;
@property(nonatomic,weak)UILabel* label;
@property(nonatomic,weak)UIButton* firstBtn;
@property(nonatomic,weak)UIButton* secondBtn;
@end

@implementation QDBookDoctorRadioCell

static NSUInteger baseTag = 666;

- (void)setupUI{

    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    CGFloat margin = 8;
    
    //切圆角
    self.layer.cornerRadius=10;
    self.layer.masksToBounds = YES;
    
    
    
    //第二个选项
    UIButton* secondBtn = [UIButton cz_textButton:@" 疑似" fontSize:16 normalColor:PPColor selectedColor:PPColor];
    [self.contentView addSubview:secondBtn];
    [secondBtn setImage:[UIImage imageNamed:@"select_default"] forState:UIControlStateNormal];
    [secondBtn setImage:[UIImage imageNamed:@"select_click"] forState:UIControlStateSelected];
    
    [secondBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-12);
        make.centerY.equalTo(self.contentView);
         make.width.offset(65);
    }];
    
    
   
    
    
    //第一个选项
    UIButton* firstBtn = [UIButton cz_textButton:@" 确诊" fontSize:16 normalColor:PPColor selectedColor:PPColor];
    [self.contentView addSubview:firstBtn];
    [firstBtn setImage:[UIImage imageNamed:@"select_default"] forState:UIControlStateNormal];
    [firstBtn setImage:[UIImage imageNamed:@"select_click"] forState:UIControlStateSelected];

    [firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(secondBtn.mas_left).offset(-16);
        make.centerY.equalTo(self.contentView);
        make.width.offset(65);
    }];
    
    
    
    UILabel* label = [UILabel cz_labelWithText:@"是否已确诊:" fontSize:18 color:PPColor];
    [self.contentView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(margin);
        make.right.equalTo(firstBtn.mas_left).offset(-20);
//        make.width.offset(80);
        make.centerY.equalTo(self.contentView);
    }];
    
    
    firstBtn.tag = 667;
    secondBtn.tag = 668;
    
    [firstBtn addTarget:self action:@selector(radioSelect:) forControlEvents:UIControlEventTouchUpInside];
    [secondBtn addTarget:self action:@selector(radioSelect:) forControlEvents:UIControlEventTouchUpInside];
    
    _firstBtn = firstBtn;
    _secondBtn = secondBtn;
    _label = label;
}


- (void)setDataDict:(NSDictionary *)dataDict{
    
    _dataDict = dataDict;
    
    _label.text = _dataDict[@"title"];
    
    NSArray<NSString*>* btnTitle = _dataDict[@"confirm"];
    
    [_firstBtn setTitle:btnTitle.firstObject forState:UIControlStateNormal];
    [_secondBtn setTitle:btnTitle.lastObject forState:UIControlStateNormal];
    
}


- (void)radioSelect:(UIButton*)sender{
    
    UIButton* lastSelectedBtn = [self viewWithTag:self.selectedBtnTag];
    lastSelectedBtn.selected = NO;
    
    
    self.selectedBtnTag = sender.tag;
    sender.selected = YES;
    
    if(self.delegate != nil && [self.delegate respondsToSelector:@selector(radioCell:withSelectIndex:)]){
        [self.delegate radioCell:self withSelectIndex:self.selectedBtnTag - baseTag];
    }
}

@end
